package com.nq.fund.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nq.common.Result;
import com.nq.fund.entity.StFundMovement;
import com.nq.fund.service.IStFundMovementService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;

 /**
 * @Description: st_fund_movement
 * @Author: jeecg-boot
 * @Date:   2024-06-03
 * @Version: V1.0
 */
@RestController
@RequestMapping("/api/stFundMovement")
@Slf4j
public class StFundMovementController {
	@Autowired
	private IStFundMovementService stFundMovementService;
	
	/**
	 * 分页列表查询
	 *
	 * @param stFundMovement
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@GetMapping(value = "/list")
	public Result<?> queryPageList(StFundMovement stFundMovement,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<StFundMovement> queryWrapper = new QueryWrapper<>();
		Page<StFundMovement> page = new Page<StFundMovement>(pageNo, pageSize);
		IPage<StFundMovement> pageList = stFundMovementService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param stFundMovement
	 * @return
	 */
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody StFundMovement stFundMovement) {
		stFundMovementService.save(stFundMovement);
		return Result.OK("Added successfully！");
	}
	
	/**
	 *  编辑
	 *
	 * @param stFundMovement
	 * @return
	 */
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody StFundMovement stFundMovement) {
		stFundMovementService.updateById(stFundMovement);
		return Result.OK("Edited successfully!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		stFundMovementService.removeById(id);
		return Result.OK("Deleted successfully!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stFundMovementService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("Batch Delete Successfully!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		StFundMovement stFundMovement = stFundMovementService.getById(id);
		if(stFundMovement==null) {
			return Result.error("No corresponding data found");
		}
		return Result.OK(stFundMovement);
	}


}
